#include"FuncService.hpp"


namespace SC_SUN
{


    FuncService::FuncService(const std::string& router, uint16_t port)
        : mService(router, port)
    {
        mOpenHandler = [](uWS::WebSocket<false,true,void*>* ws, MMFNetwork::MMFMessageHeader* pkg){};
        mCloseHandler = [](uWS::WebSocket<false,true,void*>* ws, MMFNetwork::MMFMessageHeader* pkg){};

        //添加序列化缓冲池
        for (int i = 0; i < 8192; i++)
        {
            std::vector<char> buff(MMFNetwork::MAX_MESSAGE_BUFFER_SIZE);
            mSerialInPool.PushObject(buff);
        }
    }

    FuncService::~FuncService() {}

    void FuncService::RegisterClientOpenHanlder(const Callback&& handler)
    {
        mOpenHandler = std::move(handler);
        mService.RegisterClientOpenHanlder(std::move(mOpenHandler));
    }

    void FuncService::RegisterClientCloseHanlder(const Callback&& handler)
    {
        mCloseHandler = std::move(handler);
        mService.RegisterClientCloseHanlder(std::move(mCloseHandler));
    }

    bool FuncService::Start()
    {
        return mService.Start();
    }

    void FuncService::Stop()
    {
        mService.Stop();
    }

    MMF::WsDispather<void*>& FuncService::Dispathter()
    {
        return mService.Dispathter();
    }
}